//
//  GTWeChatDynamicLinkButton.m
//  GTW
//
//  Created by Ran on 15/11/13.
//  Copyright (c) 2015年 xcode. All rights reserved.
//

#import "GTWeChatDynamicLinkButton.h"


@implementation GTWeChatDynamicLinkButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundImage:nil forState:UIControlStateNormal];
        [self setBackgroundImage:[self getSelectedImage] forState:UIControlStateHighlighted];
    }
    return self;
}

static UIImage *selectedImage;
- (UIImage *)getSelectedImage
{
    if (!selectedImage) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            selectedImage = [self imageWithColor:[UIColor lightGrayColor]];
        });
    }
    return selectedImage;
}

-(UIImage*)imageWithColor:(UIColor*)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
    
}

@end
